<template>
  <div class="secondsbLeft">
    <s-title text="近七日客流监测" :btnshow="false" />
    <div id="secondsbLeftChart"></div>
  </div>
</template>

<script>
import sTitle from "../../common/sTitle.vue";
import axios from "axios";
export default {
  name: "secondsbLeft1",
  components: {
    sTitle
  },
  data() {
    return {
      comps: [],
      ls: [
        {
          px: 6,
          ny: "2021-04",
          yps: 3,
          rps: 0,
          tjsj: "2021-09-26T19:32:47.000+00:00"
        },
        {
          px: 5,
          ny: "2021-05",
          yps: 0,
          rps: 4,
          tjsj: "2021-09-26T19:32:47.000+00:00"
        },
        {
          px: 4,
          ny: "2021-06",
          yps: 0,
          rps: 0,
          tjsj: "2021-09-26T19:32:47.000+00:00"
        },
        {
          px: 3,
          ny: "2021-07",
          yps: 0,
          rps: 0,
          tjsj: "2021-09-26T19:32:47.000+00:00"
        },
        {
          px: 2,
          ny: "2021-08",
          yps: 0,
          rps: 0,
          tjsj: "2021-09-26T19:32:47.000+00:00"
        },
        {
          px: 1,
          ny: "2021-09",
          yps: 0,
          rps: 0,
          tjsj: "2021-09-26T19:32:47.000+00:00"
        }
      ]
    };
  },
  mounted() {
    // axios.get(this.$serverIp + "getElectronicSupervision").then(res => {
    //   //res = this.ls;
    //   var echartData = { xLabel: [], goToSchool: [], goOutSchool: [] };
    //   for (var i = 0; i < res.data.length; i++) {
    //     echartData.xLabel.push(res.data[i].ny);
    //     echartData.goToSchool.push(res.data[i].px);
    //     echartData.goOutSchool.push(res.data[i].rps);
    //   }
    //   // var echartData = { xData: [], yData: [] };
    //   // echartData.yData[0] = [];
    //   // echartData.yData[1] = [];
    //   // for (let i = 0; i < res.data.length; i++) {
    //   //   echartData.xData.push(res.data[i].ny);
    //   //   echartData.yData[0].push(res.data[i].yps);
    //   //   echartData.yData[1].push(res.data[i].rps);
    //   // }
    //   this.setEchartHandle(echartData);
    // });
    this.loadPassengerFlow();
  },
  methods: {
    async loadPassengerFlow() {
      //获取当前的时间
      var myDate = new Date(); //获取今天日期
      var mon = myDate.getMonth() + 1;
      var submon = "";
      if (mon >= 10) {
        submon += mon;
      } else {
        submon += "0" + mon;
      }
      myDate.setDate(myDate.getDate() - 7);
      var dateArray = [];
      var dateTemp;
      var flag = 1;
      for (var i = 0; i < 8; i++) {
        dateTemp = myDate.getFullYear() + "-" + submon + "-" + myDate.getDate();
        dateArray.push(dateTemp);
        myDate.setDate(myDate.getDate() + flag);
      }
      var echartData = { xLabel: [], goToSchool: [], goOutSchool: [] };
      echartData.xLabel = dateArray;
      // var MultipleStatisticalGroups = [];
      // var echartData = { data1: [], data2: [], data3: [] };
      for (var i = 0; i < dateArray.length; i++) {
        //循环获取groupid，作为参数传到后台
        var params = new URLSearchParams();
        params.append("regionld", "05ef4526-060e-4131-aa27-0221ae6505b3");
        params.append("startTime", dateArray[i] + "T00:00:00+08:00");
        params.append("endTime", dateArray[i] + "T23:00:00+08:00");
        await axios
          .post(this.$videoIp + "/GetPassengerFlowRanking", params)
          .then(res => {
            echartData.goToSchool.push(res.data.data[0].peopleNumber);
          });
      }
      this.setEchartHandle(echartData);
    },
    setEchartHandle(echartData) {
      let xLabel = echartData.xLabel;
      let goToSchool = echartData.goToSchool;
      let goOutSchool = echartData.goOutSchool;
      let _echarts = this.$echarts.init(
        document.getElementById("secondsbLeftChart"),
        null,
        { devicePixelRatio: 2 }
      );
      let option = {
        backgroundColor: "rgba(255,255,255,0)",
        tooltip: {
          trigger: "axis",
          backgroundColor: "transparent",
          axisPointer: {
            lineStyle: {
              color: {
                type: "linear",
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [
                  {
                    offset: 0,
                    color: "rgba(126,199,255,0)" // 0% 处的颜色
                  },
                  {
                    offset: 0.5,
                    color: "rgba(126,199,255,1)" // 100% 处的颜色
                  },
                  {
                    offset: 1,
                    color: "rgba(126,199,255,0)" // 100% 处的颜色
                  }
                ],
                global: false // 缺省为 false
              }
            }
          },
          formatter: p => {
            let dom = `<div style="width: 79px;
	height: 50px;;color:#fff;position: relative;">
        <svg style="position: absolute;top: 50%;
    left: 50%;
    transform: translateX(-50%) translateY(-50%);" class="svg" xmlns="http://www.w3.org/2000/svg" width="100" height="71" viewBox="0 0 84 55">
      <defs>
        <style>
          .cls-1 {
            fill: #07172c;
            fill-opacity: 0.8;
            stroke: #a7d8ff;
            stroke-linejoin: round;
            stroke-opacity: 0.2;
            stroke-width: 1px;
            fill-rule: evenodd;
          }

        </style>
      </defs>
      <path id="矩形_419" data-name="矩形 419" class="cls-1" d="M266,595h74v50H266V624.046L261,620l5-3.984V595Z"
        transform="translate(-258.5 -592.5)" />
    </svg>
        <div style="padding: 4px 8px 4px 14px;display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;position: relative;z-index: 1;">
            <div style="margin-bottom: 4px;width:100%;display:${
              p[0] ? "flex" : "none"
            };justify-content:space-between;align-items:center;">
                <span style="font-size:14px;color:#7ec7ff;">${
                  p[0] ? p[0].seriesName : ""
                }</span>
                <span style="font-size:14px;color:#fff;">${
                  p[0] ? p[0].data : ""
                }</span>
            </div>
            <div style="width:100%;height:100%;display:${
              p[1] ? "flex" : "none"
            };justify-content:space-between;align-items:center;">
                <span style="font-size:14px;color:#7ec7ff;">${
                  p[1] ? p[1].seriesName : ""
                }</span>
                <span style="font-size:14px;color:#fff;">${
                  p[1] ? p[1].data : ""
                }</span>
            </div>
        </div>
    </div>`;
            return dom;
          }
        },
        legend: {
          align: "left",
          right: "5%",
          top: "0%",
          type: "plain",
          textStyle: {
            color: "#7ec7ff",
            fontSize: 16
          },
          // icon:'rect',
          itemGap: 25,
          itemWidth: 18,
          icon:
            "path://M0 2a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v0a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2z",

          data: [
            {
              name: "客流 "
            }
          ]
        },
        grid: {
          top: "18%",
          left: "15%",
          right: "5%",
          bottom: "25%"
          // containLabel: true
        },
        xAxis: [
          {
            type: "category",
            boundaryGap: false,
            axisLine: {
              //坐标轴轴线相关设置。数学上的x轴
              show: true,
              lineStyle: {
                color: "#233653"
              }
            },
            axisLabel: {
              //坐标轴刻度标签的相关设置
              textStyle: {
                color: "#7ec7ff",
                padding: 5,
                fontSize: 8
              },
              formatter: function(data) {
                return data;
              }
            },
            splitLine: {
              show: true,
              lineStyle: {
                color: "#192a44"
              }
            },
            axisTick: {
              show: false
            },
            data: xLabel
          }
        ],
        yAxis: [
          {
            name: "",
            nameTextStyle: {
              color: "#7ec7ff",
              fontSize: 16,
              padding: 10
            },
            min: 0,
            splitLine: {
              show: true,
              lineStyle: {
                color: "#192a44"
              }
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: "#233653"
              }
            },
            axisLabel: {
              show: true,
              textStyle: {
                color: "#7ec7ff",
                padding: 16
              },
              formatter: function(value) {
                if (value === 0) {
                  return value;
                }
                return value;
              }
            },
            axisTick: {
              show: false
            }
          }
        ],
        series: [
          {
            name: "客流 ",
            type: "line",
            symbol: "circle", // 默认是空心圆（中间是白色的），改成实心圆
            showAllSymbol: true,
            symbolSize: 0,
            smooth: true,
            itemStyle: {
              color: "rgba(255, 50, 50, 1)",
            },
            lineStyle: {
              color: "rgba(255, 50, 50, 1)",
            },
            areaStyle: {
              color: {
                type: "linear",
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [
                  {
                    offset: 0,
                    color: "rgba(255, 50, 50, 1)", // 0% 处的颜色
                  },
                  {
                    offset: 1,
                    color: "rgba(255, 50, 50, 0)", // 100% 处的颜色
                  },
                ],
                global: false, // 缺省为 false
              },
            },
            tooltip: {
              show: true
            },
            areaStyle: {
              //区域填充样式
              normal: {
                //线性渐变，前4个参数分别是x0,y0,x2,y2(范围0~1);相当于图形包围盒中的百分比。如果最后一个参数是‘true’，则该四个值是绝对像素位置。
                color: new this.$echarts.graphic.LinearGradient(
                  0,
                  0,
                  0,
                  1,
                  [
                    {
                      offset: 0,
                      color: "rgba(25,163,223,.3)"
                    },
                    {
                      offset: 1,
                      color: "rgba(25,163,223, 0)"
                    }
                  ],
                  false
                ),
                shadowColor: "rgba(25,163,223, 0.5)", //阴影颜色
                shadowBlur: 20 //shadowBlur设图形阴影的模糊大小。配合shadowColor,shadowOffsetX/Y, 设置图形的阴影效果。
              }
            },
            data: goToSchool
          }
        ]
      };
      _echarts.setOption(option);
    }
  }
};
</script>
<style scoped>
.secondsbLeft {
  margin-top: 20px;
}
#secondsbLeftChart {
  width: 100%;
  height: 27vh;
  margin-top: 10px;
}
</style>
 